package com.stox.core.manager;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.stox.core.dao.IndexDao;
import com.stox.core.model.Index;
import com.stox.core.model.exception.StoxException;


public class IndexManager{
	
	private IndexDao indexDao;
	private Map<String, List<Index>> exchangeCodeIndexMap;
	
	public IndexManager() {
		exchangeCodeIndexMap = new HashMap<String, List<Index>>();
		
	}
	
	public List<Index> findByExchangeCode(String exchangeCode){
		List<Index> indexes = exchangeCodeIndexMap.get(exchangeCode);
		if(indexes == null || indexes.isEmpty()){
			try {
				indexes = indexDao.findByExchangeCode(exchangeCode);
				exchangeCodeIndexMap.put(exchangeCode, indexes);
			} catch (SQLException e) {
				throw new StoxException(e);
			}
		}
		return indexes;
	}

	public IndexDao getIndexDao() {
		return indexDao;
	}

	public void setIndexDao(IndexDao indexDao) {
		this.indexDao = indexDao;
	}
	
	
	
	
}
